home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / umountfs < prev    next >
Encoding:
Text File  |  2012-03-27  |  2.8 KB  |  145 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          umountfs
  4. # Required-Start:
  5. # Required-Stop:     umountroot
  6. # Default-Start:
  7. # Default-Stop:      0 6
  8. # Short-Description: Turn off swap and unmount all local file systems.
  9. # Description:
  10. ### END INIT INFO
  11.  
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. . /lib/init/vars.sh
  14.  
  15. . /lib/lsb/init-functions
  16.  
  17. umask 022
  18.  
  19. do_stop () {
  20.     exec 9<&0 </proc/mounts
  21.  
  22.     PROTECTED_MOUNTS="$(sed -n '0,/^\/[^ ]* \/ /p' /proc/mounts)"
  23.     WEAK_MTPTS="" # be gentle, don't use force
  24.     REG_MTPTS=""
  25.     TMPFS_MTPTS=""
  26.     while read -r DEV MTPT FSTYPE REST
  27.     do
  28.         echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV $MTPT " && continue
  29.         case "$MTPT" in
  30.           /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/sys/*|/lib/init/rw)
  31.             continue
  32.             ;;
  33.           /var/run)
  34.             if [ yes = "$RAMRUN" ] ; then
  35.                 continue
  36.             fi
  37.             ;;
  38.           /var/lock)
  39.             if [ yes = "$RAMLOCK" ] ; then
  40.                 continue
  41.             fi
  42.             ;;
  43.         esac
  44.         case "$FSTYPE" in 
  45.           proc|procfs|linprocfs|sysfs|usbfs|usbdevfs|devpts)
  46.             continue
  47.             ;;
  48.           tmpfs)
  49.             TMPFS_MTPTS="$MTPT $TMPFS_MTPTS"
  50.             ;;
  51.           *)
  52.             if echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV "; then
  53.                 WEAK_MTPTS="$MTPT $WEAK_MTPTS"
  54.             else
  55.                 REG_MTPTS="$MTPT $REG_MTPTS"
  56.             fi
  57.             ;;
  58.         esac
  59.     done
  60.  
  61.     exec 0<&9 9<&-
  62.     
  63.     #
  64.     # Make sure tmpfs file systems are umounted before turning off
  65.     # swap, to avoid running out of memory if the tmpfs filesystems
  66.     # use a lot of space.
  67.     #
  68.     if [ "$TMPFS_MTPTS" ]
  69.     then
  70.         if [ "$VERBOSE" = no ]
  71.         then
  72.             log_action_begin_msg "Unmounting temporary filesystems"
  73.             fstab-decode umount $TMPFS_MTPTS
  74.             log_action_end_msg $?
  75.         else
  76.             log_daemon_msg "Will now unmount temporary filesystems"
  77.             fstab-decode umount -v $TMPFS_MTPTS
  78.             log_end_msg $?
  79.         fi
  80.     fi
  81.  
  82.     #
  83.     # Deactivate swap
  84.     #
  85.     if [ "$VERBOSE" = no ]
  86.     then
  87.         log_action_begin_msg "Deactivating swap"
  88.         swapoff -a >/dev/null
  89.         log_action_end_msg $?
  90.     else
  91.         log_daemon_msg "Will now deactivate swap"
  92.         swapoff -a -v
  93.         log_end_msg $?
  94.     fi
  95.  
  96.     #
  97.     # Unmount local filesystems
  98.     #
  99.     if [ "$WEAK_MTPTS" ]; then
  100.         # Do not use -f umount option for WEAK_MTPTS
  101.         if [ "$VERBOSE" = no ]
  102.         then
  103.             log_action_begin_msg "Unmounting weak filesystems"
  104.             fstab-decode umount -r -d $WEAK_MTPTS
  105.             log_action_end_msg $?
  106.         else
  107.             log_daemon_msg "Will now unmount weak filesystems"
  108.             fstab-decode umount -v -r -d $WEAK_MTPTS
  109.             log_end_msg $?
  110.         fi
  111.     fi
  112.     if [ "$REG_MTPTS" ]
  113.     then
  114.         if [ "$VERBOSE" = no ]
  115.         then
  116.             log_action_begin_msg "Unmounting local filesystems"
  117.             fstab-decode umount -f -r -d $REG_MTPTS
  118.             log_action_end_msg $?
  119.         else
  120.             log_daemon_msg "Will now unmount local filesystems"
  121.             fstab-decode umount -f -v -r -d $REG_MTPTS
  122.             log_end_msg $?
  123.         fi
  124.     fi
  125. }
  126.  
  127. case "$1" in
  128.   start)
  129.     # No-op
  130.     ;;
  131.   restart|reload|force-reload)
  132.     echo "Error: argument '$1' not supported" >&2
  133.     exit 3
  134.     ;;
  135.   stop)
  136.     do_stop
  137.     ;;
  138.   *)
  139.     echo "Usage: $0 start|stop" >&2
  140.     exit 3
  141.     ;;
  142. esac
  143.  
  144. :
  145.